// storage.js
import request from '@/utils/request'

// 入库相关
export function getStorageInList() {
    return request({
        url: '/api/storage-in',
        method: 'get'
    })
}

export function addStorageIn(data) {
    return request({
        url: '/api/storage-in',
        method: 'post',
        data
    })
}

export function updateStorageIn(data) {
    return request({
        url: '/api/storage-in',
        method: 'put',
        data
    })
}

export function deleteStorageIn(id) {
    return request({
        url: `/api/storage-in/${id}`,
        method: 'delete'
    })
}

export function getStorageInById(id) {
    return request({
        url: `/api/storage-in/${id}`,
        method: 'get'
    })
}

export function getStorageInByOrderNumber(orderNumber) {
    return request({
        url: `/api/storage-in/order/${orderNumber}`,
        method: 'get'
    })
}

export function getStorageInByPortId(portId) {
    return request({
        url: `/api/storage-in/port/${portId}`,
        method: 'get'
    })
}

export function getStorageInByCompanyId(companyId) {
    return request({
        url: `/api/storage-in/company/${companyId}`,
        method: 'get'
    })
}

// 出库相关
export function getStorageOutList() {
    return request({
        url: '/api/storage-out',
        method: 'get'
    })
}

export function addStorageOut(data) {
    return request({
        url: '/api/storage-out',
        method: 'post',
        data
    })
}

export function updateStorageOut(data) {
    return request({
        url: '/api/storage-out',
        method: 'put',
        data
    })
}

export function deleteStorageOut(id) {
    return request({
        url: `/api/storage-out/${id}`,
        method: 'delete'
    })
}

export function getStorageOutById(id) {
    return request({
        url: `/api/storage-out/${id}`,
        method: 'get'
    })
}

export function getStorageOutByOrderNumber(orderNumber) {
    return request({
        url: `/api/storage-out/order/${orderNumber}`,
        method: 'get'
    })
}

export function getStorageOutByPortId(portId) {
    return request({
        url: `/api/storage-out/port/${portId}`,
        method: 'get'
    })
}

export function getStorageOutByCompanyId(companyId) {
    return request({
        url: `/api/storage-out/company/${companyId}`,
        method: 'get'
    })
}

// 统计相关
export function getStorageSummary() {
    return request({
        url: '/api/storage/summary',  // 与后端一致
        method: 'get'
    })
}

export function getAvailableInRecords() {
    return request({
        url: '/api/storage/records/available',  // 更清晰的路径
        method: 'get'
    })
}
// 在storage.js中添加

// 按日期范围查询
export function getRecordsByDateRange(startDate, endDate) {
    return request({
        url: '/api/storage/records/range',
        method: 'get',
        params: {
            start: startDate,
            end: endDate
        }
    })
}

// 获取统计信息
export function getStorageStatistics() {
    return request({
        url: '/api/storage/statistics',
        method: 'get'
    })
}

// 批量入库
export function batchImportStorageIn(data) {
    return request({
        url: '/api/storage-in/batch',
        method: 'post',
        data
    })
}

// 批量出库
export function batchImportStorageOut(data) {
    return request({
        url: '/api/storage-out/batch',
        method: 'post',
        data
    })
}

// 清空入库表
export function clearStorageIn() {
    return request({
        url: '/api/storage-in/clear',
        method: 'post'
    })
}

// 清空出库表
export function clearStorageOut() {
    return request({
        url: '/api/storage-out/clear',
        method: 'post'
    })
}